
class BaseMessage(object):
    def __init__(self, xml_data):
        self.ToUserName = xml_data.find('ToUserName').text
        self.FromUserName = xml_data.find('FromUserName').text
        self.CreateTime = xml_data.find('CreateTime').text
        self.MsgType = xml_data.find('MsgType').text
        if self.MsgType != 'event':
            self.MsgId = xml_data.find('MsgId').text


class TextMessage(BaseMessage):
    def __init__(self, xml_data):
        BaseMessage.__init__(self, xml_data)
        # super(TextMessage, self).__init__(xml_data)
        self.Content = xml_data.find('Content').text


class ImageMessage(BaseMessage):
    def __init__(self, xml_data):
        super(ImageMessage, self).__init__(xml_data)
        self.PicUrl = xml_data.find('PicUrl').text
        self.MediaId = xml_data.find('MediaId').text


class VoiceMessage(BaseMessage):
    def __init__(self, xml_data):
        super(VoiceMessage, self).__init__(xml_data)
        self.MediaId = xml_data.find('MediaId').text
        self.Format = xml_data.find('Format').text


class EventMessage(BaseMessage):
    def __init__(self, xml_data):
        super(EventMessage, self).__init__(xml_data)
        self.Event = xml_data.find('Event').text
        self.EventKey = xml_data.find('EventKey').text


